import cv2
import numpy as np

# 读取图像
image = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)

# 定义结构元素
kernel = np.ones((5, 5), np.uint8)

# 应用闭运算
closing_image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)

# 显示结果
cv2.imshow('Original Image', image)
cv2.imshow('Closing Image', closing_image)
cv2.waitKey(0)
cv2.destroyAllWindows()